package com.va.feedback.component;

import org.json.JSONException;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.va.feedback.FeedbackItemConstants;

public abstract class AbstractFeedback extends RelativeLayout{
	
	protected Context context;
	protected TextView questionWidget;
	protected int qid;

	/**
	 * Constructor for the AbstractFeedback
	 * @param context
	 */
	public AbstractFeedback(Context context) {
		super(context);
		this.context = context;
	}

	/**
	 * Adds the question TextView
	 */
	protected void addQuestionWidget() {
		questionWidget = new TextView(context);
		RelativeLayout.LayoutParams questionWidgetLayout = new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		questionWidget.setId(1);
		questionWidget.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
		questionWidget.setTextSize(20);
		questionWidget.setLayoutParams(questionWidgetLayout);
		this.addView(questionWidget);//, questionWidgetLayout);
	}
	
	/**
	 * Adds the Answer component. Each feedback type has its own 
	 * implementation of their component
	 */
	protected abstract void addAnswerComponent();
	
	/**
	 * Debug method which can be used universally by any method
	 * Take care in using this method, app_client and app_secret should never be added 
	 * to a debug message. Or else you may be leaking your secret info.
	 * @param message
	 */
	protected void debug(String message) {
		if (FeedbackItemConstants.DEBUG) {
			if (message != null)
				Log.d("AbstractFeedback", message);
		}
	}
	
	/**
	 * This method sets various properties for the components
	 * @param type type of the property whose value to set
	 * @param value value of the property to be set
	 */
	public void setProperty(String type, Object value) {
		if (type.equals(FeedbackItemConstants.QUESTION_ID)) {
			qid = (Integer) value;
		} else {
			setComponentProperty(type, value);
		}
	}
	
	protected abstract void setComponentProperty(String type, Object value);

	/**
	 * This method will be called when the response is to be collected from the component
	 * @return response of the user
	 * @throws JSONException
	 */
	public abstract Object getFeedback() throws JSONException;

}
